Here in this advance CSS tutorial, we will be going to learn how to create tooltip using CSS.
ToolTip
A tooltip is a popup text which is used to tell the extra information about the element content when the user hovers the mouse or cursor over the element content. In CSS we do not have a specific property to create a tooltip, so we use some logic to create one. The example gives blow creates a tooltip that shows the extra information if the user hovers the mouse over the content.
Behind the code
HTML
In the above example, we created a container
<div class="tooltip">
which contain the
tooltip
and when the user hove over its content the
tooltip
text shows up. In the same div tag, we defined a
<span>
element with
class=”tiptext”
which contains the tooltip text.
CSS
For the
tooltip
class we use the
position:relative
, because we want the tooltip text
postion:absolute
. And the
tiptext
class v
isibility:hidden
make the tooltip text hidden until the user hover over the <div> content.
Position the Tooltip Text
We can set the position of the tooltip text by mentioning the properties like left, top, bottom, and right.
Right Positioning Tooltip Example
Left Positioning Tooltip Example
Top Positioning Tooltip Example
Bottom Positioning Tooltip Example
Summary
- Tooltip is a pop-up text which is used to provide the extra information about the element content.
- Make sure that when the user hover over the element then only the tooltip text should be displayed.